package com.pansoft.nfc;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;

import com.pansoft.openplanet.R;
import com.pansoft.openplanet.widget.TCLoadingDataView;

/**
 * nfc冷钱包提醒类
 *
 * @author wang
 */
public class NfcAlertUtils {

    /**
     * 转换冷热钱包成功提示
     *
     * @param activity activity
     */
    public static void showConvertSuccess(final Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity)
                .setTitle(R.string.op_wallet_convert_success)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finishAffinity();
                    }
                }).create().show();
    }

    /**
     * Create a dialog that send user to NFC settings if NFC is off.
     * Alternatively the user can chose to use the App in editor only
     * mode or exit the App.
     */
    public static void createNfcEnableDialog(final Activity activity) {
        new AlertDialog.Builder(activity)
                .setTitle(R.string.open_planet_open_nfc_function)
                .setMessage(R.string.open_planet_open_nfc)
                .setPositiveButton(R.string.open_planet_nfc_next, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Goto NFC Settings.
                        if (Build.VERSION.SDK_INT >= 16) {
                            activity.startActivity(new Intent(
                                    Settings.ACTION_NFC_SETTINGS));
                        } else {
                            activity.startActivity(new Intent(
                                    Settings.ACTION_WIRELESS_SETTINGS));
                        }
                    }
                }).setNegativeButton(R.string.common_text_cancel, null)
                .create()
                .show();
    }

    /**
     * 不支持的nfc卡片提示
     *
     * @param activity activity
     */
    public static void showNfcNotSupport(Activity activity) {
        new AlertDialog.Builder(activity)
                .setTitle(R.string.open_planet_unsupported_card)
                .setMessage(R.string.open_planet_this_nfc_card_not_supported)
                .setNegativeButton(R.string.common_text_confirm, null)
                .create()
                .show();
    }

    /**
     * 卡片操作失败
     */
    public static void showNfcFailAlert(Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(R.string.op_sth_wrong_put_card_again)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }

    /**
     * 空卡提示
     *
     * @param activity activity
     */
    public static void showEmptyCardAlert(Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(R.string.op_no_data_put_card_again)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }

    /**
     * 读取卡片不正确提示
     */
    public static void showWrongCardAlert(Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(R.string.op_incorrect_address_put_card_again)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }

    /**
     * 写操作时非空卡提示
     */
    public static void showNonEmptyCardAlert(Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(R.string.op_card_has_data_change_card)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }

    /**
     * 卡号错误
     */
    public static void showNoWrong(Activity activity) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(R.string.star_asset_card_no_wrong)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }

    /**
     * 显示弹框
     */
    public static void showWrongMsg(Activity activity, String msg) {
        TCLoadingDataView.dismiss();
        new androidx.appcompat.app.AlertDialog.Builder(activity).setTitle(R.string.common_text_hint)
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton(R.string.common_text_confirm, null)
                .setNegativeButton(R.string.common_text_cancel, null)
                .create().show();
    }
}
